package hu.diploma.web.shared;

import hu.diploma.web.client.Messages;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;

public class EnumUtil {
	private final static Messages messages = GWT.create(Messages.class);

	static List<ComboBoxItem> phoneItems;
	static Map<String, List<ComboBoxItem>> comboMap;

	public static List<ComboBoxItem> getPhoneComboBox() {

		if (phoneItems == null) {
			phoneItems = new ArrayList<ComboBoxItem>();
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_ASSISTANT.toString(), messages.PHONE_ASSISTANT()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_FAX_WORK.toString(), messages.PHONE_FAX_WORK()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_HOME.toString(), messages.PHONE_HOME()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_MOBILE.toString(), messages.PHONE_MOBILE()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_OTHER.toString(), messages.PHONE_OTHER()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_PAGER.toString(), messages.PHONE_PAGER()));
			phoneItems.add(new ComboBoxItem(DataSubType.PHONE_WORK.toString(), messages.PHONE_WORK()));

		}

		return phoneItems;

	}

	public static ComboBoxItem getPhoneComboBoxValue(String value) {
		for (ComboBoxItem boxItem : getPhoneComboBox()) {
			if (boxItem.getValue().equals(value)) {
				return boxItem;
			}
		}
		return null;
	}

	public static List<ComboBoxItem> getComboBoxListWithType(String value) {
		if (comboMap == null) {
			comboMap = new HashMap<String, List<ComboBoxItem>>();
			comboMap.put("PHONE", getPhoneComboBox());

		}

		return comboMap.get(value);
	}
}
